const state = {
  course: new Array(),
  courseSelectModel: ''
}
const mutations = {
  SET_COURSE: (state, data) => {
    try {
      for (let i = 0; i < state.course.length; i++) {
        if (state.course[i].id == data.id) {
            state.course.splice(i, 1)
        }
      }
    } catch (e) {
    }
      state.course.push(data)
  },
  SET_COURSE_SELECT_MODEL: (state, data) => {
      state.courseSelectModel=data
  },
  CLEAN_COURSE: (state) => {
    state.course = new Array()
    state.courseSelectModel=''
  },
  CLEAN_COURSE_DATA: (state) => {
    state.course = new Array()
  }
}

const actions = {
  // 设置课程等级
  setCourse({ commit }, data) {
    commit('SET_COURSE', data)
  },
  // 设置选择模式
  setCourseSelectModel({ commit }, data) {
    commit('SET_COURSE_SELECT_MODEL', data)
  },
  // 清空代理-全部清空
  cleanCourse({ commit }) {
    commit('CLEAN_COURSE')
  },
  // 清空代理-选中数据
  cleanCourseData({ commit }) {
    commit('CLEAN_COURSE_DATA')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

